/**
 * 封装 uni.showModal
 * @param title 标题
 * @param content 内容
 * @param confirmText 确认按钮文本
 * @param cancelText 取消按钮文本
 * @returns Promise<boolean> 返回用户是否点击了确认
 */
export function useModal() {
  const showModal = (
    title: string,
    content: string,
    confirmText: string = '确定',
    cancelText: string = '取消'
  ): Promise<boolean> => {
    return new Promise((resolve) => {
      uni.showModal({
        title,
        content,
        confirmText,
        cancelText,
        success: (res) => {
          if (res.confirm) {
            resolve(true)
          } else if (res.cancel) {
            resolve(false)
          }
        }
      })
    })
  }

  return {
    showModal
  }
}
